//
//  NewFeatureCell.m
//  OCMicroBlog
//
//  Created by 002 on 15/11/6.
//  Copyright © 2015年 002. All rights reserved.
//

#import "NewFeatureCell.h"
#import "Masonry.h"
#import "UIButton+Extention.h"

@interface NewFeatureCell ()

// 新特性图片
@property(nonatomic,strong) UIImageView *iconView;

// 开始体验按钮
@property(nonatomic,strong) UIButton *startButton;

@end

@implementation NewFeatureCell

// 开始按钮监听方法
- (void)clickStartButton {
    
    // 发送通知 - 进入主界面
    [[NSNotificationCenter defaultCenter] postNotificationName:WBSwitchRootViewControllerNotification object:nil];
}

// 构造函数
- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    [self setupUI];
    return self;
}

#pragma mark - 界面布局
- (void)setupUI {
    
    // 1. 添加控件
    [self.contentView addSubview:self.iconView];
    [self.contentView addSubview:self.startButton];
    
    // 2. 指定位置
    self.iconView.frame = self.contentView.bounds;
    
    // 3. 页面布局
    // 1) 图片
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView.mas_top);
        make.left.equalTo(self.contentView.mas_left);
        make.right.equalTo(self.contentView.mas_right);
        make.bottom.equalTo(self.contentView.mas_bottom);
    }];
    
    // 2) ‘开始体验’ 按钮
    [self.startButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.bottom.equalTo(self.contentView.mas_bottom).multipliedBy(0.7);
    }];
    
    // 4. 添加监听方法
    [self.startButton addTarget:self action:@selector(clickStartButton) forControlEvents:UIControlEventTouchUpInside];
}

// 设置属性
- (void)setImageIndex:(NSInteger)imageIndex {
    _imageIndex = imageIndex;
    
    self.iconView.image = [UIImage imageNamed:[NSString stringWithFormat:@"new_feature_%ld",imageIndex]];
        self.startButton.hidden = true;
}

/**
 *  显示按钮动画
 */
- (void)showStartButtonAnim {
    
    // 初始化按钮属性
    self.startButton.hidden = false;
    self.startButton.transform = CGAffineTransformMakeScale(0, 0);
    self.startButton.userInteractionEnabled = false;
    
    // 执行动画
    [UIView animateWithDuration:1.6
                          delay:0
         usingSpringWithDamping:0.6
          initialSpringVelocity:10
                        options:0
                     animations:^{
        
        self.startButton.transform = CGAffineTransformIdentity;
    }
                     completion:^(BOOL finished) {
        self.startButton.userInteractionEnabled = true;
    }];
}

#pragma mark - 懒加载控件
// 新特性图片
- (UIImageView *)iconView {
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
    }
    return _iconView;
}

// 开始按钮
- (UIButton *)startButton {
    if (!_startButton) {
        _startButton = [UIButton initWithTitle:@"开始体验" color:[UIColor whiteColor] fontSize:14 backImageName:@"new_feature_finish_button"];
        _startButton.hidden = true;
    }
    return _startButton;
}

@end
